﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NWN.GDY.Service.Core;
using NWN.GDY.Service.Core.HandcardCreator;
using System.Security.Cryptography;
using NWN.GDY.Service.Entity;  

namespace NWN.GDY.Web
{
    public partial class Test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //是否有桌号
            //根据桌号取桌信息
            //初始化游戏人员信息
            //初始化空位信息
            //初始化出牌信息
            //初始化聊天信息
            byte[] bytes = new byte[4];        // 4字节用于转换为一个Int32数据   
            RNGCryptoServiceProvider Gen = new RNGCryptoServiceProvider();
            for (int i = 0; i < 50; i++)
            {
                Gen.GetBytes(bytes);
                //一到六的随机数
                int number = BitConverter.ToInt32(bytes, 0) & Int32.MaxValue;
                number=number % 6 + 1;
                Response.Write("随机取"+number.ToString()+"张<br/>");
                //List<Card> cardsnoorder = (from c in RoomBC.GetCardsInstance() where c.CardType <= 6 select c).OrderBy(p => Guid.NewGuid()).Take(number).ToList();
                List<Card> cardsnoorder = (from c in RoomBC.GetCardsInstance() where c.CardType <= 6 && c.CardType >= 4 && c.CardNum > 8 select c).OrderBy(p => Guid.NewGuid()).Take(number).ToList();
                //写死牌
                //List<int> chosencards = new List<int>();
                //chosencards.Add(10);
                //chosencards.Add(11);
                //chosencards.Add(12);
                //chosencards.Add(25);
                //chosencards.Add(20);
                //List<Card> cardsnoorder = (from c in RoomBC.GetCardsInstance() where chosencards.Contains(c.CardNum) && c.CardType >= 4 && c.CardType <= 6 select c).OrderBy(p => Guid.NewGuid()).Take(6).ToList();
                List<Card> cards = (from c in cardsnoorder orderby c.CardNum select c).ToList();
                AbstractHDCreator ct = new BombCreator(new StraightCreator(new DoubleCreator(new SingleCreator())));
                List<HandCard> hclist = new List<HandCard>();
                ct.CreateHandCard(cards, RoomBC.GetCardsInstance(), hclist);
                foreach (Card c in cards)
                {
                    //Response.Write(c.CardNum + "_" + c.CardType + "_" + c.SimpleName + "&nbsp;&nbsp;&nbsp;&nbsp;");
                    Response.Write(c.SimpleName + "&nbsp;&nbsp;&nbsp;&nbsp;");
                }
                Response.Write("<br/>");
                foreach (HandCard hc in hclist)
                {
                    Response.Write(hc.ToSimpleLog() + "<br/>");
                }
            }   
        }

        protected void btnStart_Click(object sender, EventArgs e)
        {
            new GDYEngine().NewTable("123", "whykidding", Session.SessionID, "无尼南委宁呢");
            Response.Redirect("Test.aspx");
        }
    }
}
